// pages/ratestart/ratestart.js
const app = getApp()
Page({
  data: {
    content:'',
    textstr:'',
    flag:0,
    textlist:[
      {
        choose: false,
      val:'0',
      name:'趣味创新',
     },{
        choose: false,
        value: '1',
        name: '操作流畅',
      },{
        choose: false,
        value: '2',
        name: '规则易懂',
      },{
        choose: false,
        value: '3',
        name: '界面友好',
      },{
        choose: false,
        value: '4',
        name: '心意慢慢',
      },{
        choose: false,
        value: '5',
        name: '还会购买',
      },]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  myorder(){   //我的订单
    wx.navigateTo({
      url: '/pages/myorder/myorder'
    })
  },
  changeColor1: function () {  //星星颜色
    var that = this;
    that.setData({
      flag: 1
    });
  },
  changeColor2: function () {
    var that = this;
    that.setData({
      flag: 2
    });
  },
  changeColor3: function () {
    var that = this;
    that.setData({
      flag: 3
    });
  },
  changeColor4: function () {
    var that = this;
    that.setData({
      flag: 4
    });
  },
  changeColor5: function () {
    var that = this;
    that.setData({
      flag: 5
    });
  },
  
  choosetext(e){  //选择标签  
    let index = e.currentTarget.dataset.index;
    let text = e.currentTarget.dataset.text;
    var textlist = this.data.textlist;
    textlist[index].choose = !textlist[index].choose
    this.setData({
      textlist: textlist
    })
    let temp = [];
    for (var i = 0; i < this.data.textlist.length;i++){
      if (this.data.textlist[i].choose==true){
        temp.push(this.data.textlist[i].name);    
      }
    
    }
    this.setData({
      str: temp.join(',')
    })
  },
  contents(e) {  //评价内容
  if (parseInt(e.detail.value.length) >= 100){
      wx.showToast({
        title: '最多输入36个字符',
        duration: 2000,
        icon: 'none'
      })
    }
    this.setData({
      content: e.detail.value
    })
  },
  submit(){  //提交评论
  if(this.check()){
    wx.showLoading({
      title: '提交中...',
     })
    wx.request({   //获取购物车列表
      url: app.globalData.url + '/jxb/order/comment',
      method: 'GET',
      data: {
        token: wx.getStorageSync('token'),
        uid: wx.getStorageSync('uid'),
        lable: this.data.str,
        content: this.data.content,
        socre: this.data.flag,
      },
      success: function (res) {
        wx.hideLoading()
        if(res.data.code==0){
          wx.showModal({
            title: '提交成功',
            confirmText: '返回首页',
            confirmColor: '#28A8F9',
            showCancel: false,
            content: '感谢您对我们的服务提供宝贵的意见,我们将继续竭诚为您服务！',
            success: function (res) {
              if (res.confirm) {
                wx.switchTab({
                  url: '/pages/index/index',
                })
              } else if (res.cancel) {
                return;
              }
            },
            fail:function(){
              wx.showToast({
                title: '网络错误',
                icon:'none',
                duration:2000
              })
            },
            complete:function(){
              wx.hideLoading()
            }
          })
        }
          
      },

    })
  }
},
  check(){
    if (this.data.flag == 0 || this.data.str == '' || this.data.content == '') {
      let content = '';
      this.data.flag == '' ? content = '亲，请选择满意度哟~' : this.data.str == '' ? content = '亲，请选择标签评价哟~' : this.data.content == '' ? content = '亲，请填写您的反馈体验哟' : ''
      wx.showModal({
        title: '稍等一下',
        confirmText: '好的',
        confirmColor: '#28A8F9',
        showCancel: false,
        content: content,
        success: function (res) {
          if (res.confirm) {
          } else if (res.cancel) {
            return;
          }
        }
      })
    } else if (this.data.flag !== 0 && this.data.str !== '' && this.data.content !== ''){
      return true;
    }
  }
})